<!doctype html>
<html class="no-js">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <title>获取授权</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="Cache-Control" content="no-siteapp"/>
    <script src="/public/home/plugins/jquery-2.1.4.js"></script>
    <script src="http://g.alicdn.com/dingding/open-develop/1.9.0/dingtalk.js"></script>
</head>
<body>
<script>
    dd.ready(function(){
        dd.runtime.permission.requestAuthCode({
            corpId: "{:config('dingtalk.CORPID')}", //企业id
            onSuccess: function (info) {
                $.ajax({
                    url: "{:url('auth')}",
                    type:"POST",
                    data: {"code":info.code},
                    dataType:'json',
                    async:false,
                    timeout: 900,
                    success: function (res, status, xhr) {
                        if (res.code === 1) {
                            location.href = "{:url('Index/index')}";
                        } else {
                            alert('获取用户信息错误: ' + res.msg);
                        }
                    },
                    error: function (xhr, errorType, error) {
                        alert(errorType + ', ' + error);
                    }
                });
            },
            onFail: function (err) {
                alert('获取授权失败: ' + JSON.stringify(err));
            }
        });
    });

</script>
</body>
</html>